package com.yili.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.yili.oa.dao.FtAccountDetailsMapper;
import com.yili.oa.dao.extend.FtAccountDetailsExtendMapper;
import com.yili.oa.entity.FtAccountDetailsSearch;
import com.yili.oa.models.Admin;
import com.yili.oa.models.FtAccountDetails;
import com.yili.oa.service.AdminService;
import com.yili.oa.service.FtAccountDetailsService;
import com.yili.oa.utils.annotate.DataBase;
import com.yili.oa.vo.response.AccountDetailStatisticsRes;
import com.yili.oa.vo.response.FtAccountDetailsRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@DataBase("lyt_game_db")
@Transactional(value = "transactionManager")
public class FtAccountDetailsServiceImpl implements FtAccountDetailsService {

    @Autowired
    private  FtAccountDetailsExtendMapper ftAccountDetailsExtendMapper;

    @Autowired
    private FtAccountDetailsMapper mapper;

    @Autowired
    private AdminService adminService;


    @Override
    public Integer add(FtAccountDetails ftAccountDetails) {
        long time = new Date().getTime();
        ftAccountDetails.setTradeTime(time);
        return mapper.insert(ftAccountDetails);
    }

    @Override
    public List<FtAccountDetailsRes> get(FtAccountDetailsSearch searchBase) {
        List<FtAccountDetailsRes> ftAccountDetailsRes = ftAccountDetailsExtendMapper.get(searchBase);
        return ftAccountDetailsRes;
    }

    @Override
    public AccountDetailStatisticsRes getSum(Long userId) {
        AccountDetailStatisticsRes accountDetailsRes = new AccountDetailStatisticsRes();
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        List<Integer> list3 = new ArrayList<>();
        List<Integer> list4 = new ArrayList<>();
        list1.add(2);
        list2.add(3);
        list3.add(5);
        list4.add(8);
        accountDetailsRes.setAccountBalances(ftAccountDetailsExtendMapper.getAccountBlance(userId));
        accountDetailsRes.setDeposit(ftAccountDetailsExtendMapper.getSum("income",userId,list1));
        accountDetailsRes.setWithdraw(ftAccountDetailsExtendMapper.getSum("expense",userId,list2));
        accountDetailsRes.setDiscount(ftAccountDetailsExtendMapper.getSum("income",userId,list3));
        accountDetailsRes.setRebate(ftAccountDetailsExtendMapper.getSum("income",userId,list4));
        return accountDetailsRes;
    }


}
